package client_listen_update_files;



import java.io.File;

/**
 * this class manage the communication 
 * between the client and the server, and
 * provide and API to notify changes to server.
 * 
 * all client's requests to server goes
 * through this class.
 * 
 * --Singleton--
 * 
 * @author Yoav
 *
 */
public class ServerCommManager {
	private IteractionWithServer iteraction;
	
	//--Singleton implementation--//	
	private static class ServerCommHolde{
		static final ServerCommManager serverCommHolder=new ServerCommManager();
	}
	
	//constructor
	private ServerCommManager() {
		iteraction=new IteractionWithServer("http://localhost:9991",ConfigManager.get().getUserName()
				,ConfigManager.get().getPassword());
	}
	/**
	 * get ServerCommManager instance
	 * @return ServerCommManager instance
	 */
	public static ServerCommManager getCommManager(){
		return ServerCommHolde.serverCommHolder;
	}
	
	/**
	 * send request of a modified file to server
	 * or if new folder created
	 * @param file modified file
	 * @param path file's path
	 */
	public void sendFile(File file,String path){
			iteraction.sendFileToServlet(file,path);
		
	}
	
	/**
	 * send delete request of a deleted file or folder
	 * @param filePath file/dir path
	 */
	public void deleteFile(String filePath){
		iteraction.deleteFileFromServlet(filePath);
	}
	
	/**
	 * send download request of a file ,that was modified, from server
	 * @param checkSum file's checkSum
	 * @param file File instance of a file to put content in
	 */
	public void downloadFile(String checkSum,File file){		
		iteraction.downloadFileFromServlet(checkSum, file);
		
	}
	
	/**
	 * send rename request of a file/dir that was renamed
	 * @param oldName old file/dir name
	 * @param newName new file/dir name
	 */
	public void rename(String oldName, String newName) {
		iteraction.rename(oldName, newName);
		
	}
	
}
